import { log, time, timeStamp } from 'console';
import { defineStore } from 'pinia';
import { listGet, listWhereGet } from '../api/equipment/equipment';
import { whereType } from '../types/suTypes/eventWhereType'
interface pageType {
    page: number;
    limit: number;
}
interface ListType {
    startTime: string,
    eventSource: string
    eventStart: number
    alarmStart: number
    restoreTime: string
    equipmentNum: string
    equipmentAddress: string
}
export const useDacive = defineStore('run', {
    state: () => ({
        equipmentList: <Array<ListType>>[],
        wheres: <whereType>{
            statevalue: null,
            typevalue: null,
            timevalue: null,
            page: 1,
            limit: 10,
            alarmStart: null
        }

    }),
    actions: {
        async runAllAction() {
            let res = await listGet();
            console.log(res);
            this.equipmentList = res.data.results
        },
        // 条件查询设备数据
        async runWhereAction(whereData: whereType) {
            this.wheres.alarmStart = whereData.alarmStart
            this.wheres.statevalue = whereData.statevalue
            this.wheres.typevalue = whereData.typevalue
            this.wheres.timevalue = whereData.timevalue
            let res = await listWhereGet(this.wheres)
            this.equipmentList = res.data.results
            console.log(this.wheres);

        },
        // 分页查询
        async pageWhereAction(pages: pageType) {
            this.wheres.page = pages.page
            this.wheres.limit = pages.limit
            let res = await listWhereGet(this.wheres)
        },
        // 事件状态的查询
        async stateWhereAction(state: number | null) {
            this.wheres.alarmStart = null
            this.wheres.statevalue = state
            this.wheres.timevalue = null
            this.wheres.typevalue = null
            this.wheres.page = 1
            let res = await listWhereGet(this.wheres)
            this.equipmentList = res.data.results
        },
        // 报警状态查询
        async alarmWhereAction(state: null | number) {
            this.wheres.alarmStart = state
            this.wheres.statevalue = null
            this.wheres.timevalue = null
            this.wheres.typevalue = null
            this.wheres.page = 1
            let res = await listWhereGet(this.wheres)
            this.equipmentList = res.data.results
        }
    }
}) 